﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Administrator
{
    public partial class fAccess : Form
    {
        public fAccess()
        {
            InitializeComponent();
        }
       
        private void fAccess_Load(object sender, EventArgs e)
        {
            tbProvider.Text = cDbOracle.DbAccess.Provider;
            tbServer.Text = cDbOracle.DbAccess.Server;
            tbInstance.Text = cDbOracle.DbAccess.Instance;
            tbScheme.Text = cDbOracle.DbAccess.Scheme;
            tbUserName.Text = cDbOracle.DbAccess.UserName;
            tbPassword.Text = cDbOracle.DbAccess.Password;
            cbSource.Text = cDbOracle.DbAccess.Source;
            chbSaveIdentification.Checked = cDbOracle.DbAccess.SaveIdentification;
        }
        private void btnOk_Click(object sender, EventArgs e)
        {
            cDbOracle.DbAccess.Provider = tbProvider.Text;
            cDbOracle.DbAccess.Server = tbServer.Text;
            cDbOracle.DbAccess.Instance = tbInstance.Text;
            cDbOracle.DbAccess.Scheme = tbScheme.Text;
            cDbOracle.DbAccess.UserName = tbUserName.Text;
            cDbOracle.DbAccess.Password = tbPassword.Text;
            cDbOracle.DbAccess.Source = cbSource.Text;
            cDbOracle.DbAccess.SaveIdentification = chbSaveIdentification.Checked;
            if (cDbOracle.OpenConnection())
            {
                //if (cDbOracle.CheckProgrammDBConnection("ceAdmin.exe"))
                //{
                //    if (cDbOracle.DbConnect.State == ConnectionState.Open) cDbOracle.DbConnect.Close();                    
                //    MessageBox.Show("Один экземпляр программы уже подключен к данной БД. Второе подключение запрещено", cConst.ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);                
                //    return;
                //}
                this.ShowInTaskbar = false;
                Application.DoEvents();
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                Close();                
            }
        }
        private void btnClose_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            Close();
        }
        private void fAccess_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13) btnOk_Click(btnOk, null);
            if (e.KeyChar == 27) btnClose_Click(btnClose, null);
        }
    }
}
